package com.designschool.base.util;

/***
 * 
 * @项目名:base  
 * 
 * @类名:ObjectUtils.java  
 * 
 * @创建人:shibaotong
 *
 * @类描述:Object的操作工具
 * 
 * @date:2014-1-3
 * 
 * @Version:1.0 
 *
 *****************************************
 */
public class ObjectUtils {

    /***
     * 比较两个对象
     * @param actual
     * @param expected
     * @return
     */
    public static boolean isEquals(Object actual, Object expected) {
        return actual == expected || (actual == null ? expected == null : actual.equals(expected));
    }

    /***
     * 复制long数组
     * @param source
     * @return
     */
    public static Long[] transformLongArray(long[] source) {
        Long[] destin = new Long[source.length];
        for (int i = 0; i < source.length; i++) {
            destin[i] = source[i];
        }
        return destin;
    }
    /***
     * 复制Long数组
     * @param source
     * @return
     */
    public static long[] transformLongArray(Long[] source) {
        long[] destin = new long[source.length];
        for (int i = 0; i < source.length; i++) {
            destin[i] = source[i];
        }
        return destin;
    }

    /***
     * 复制int数组
     * @param source
     * @return
     */
    public static Integer[] transformIntArray(int[] source) {
        Integer[] destin = new Integer[source.length];
        for (int i = 0; i < source.length; i++) {
            destin[i] = source[i];
        }
        return destin;
    }

    /***
     * 复制Integer数组
     * @param source
     * @return
     */
    public static int[] transformIntArray(Integer[] source) {
        int[] destin = new int[source.length];
        for (int i = 0; i < source.length; i++) {
            destin[i] = source[i];
        }
        return destin;
    }

    /***
     * 比较两个对象
     * @param v1
     * @param v2
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static <V> int compare(V v1, V v2) {
        return v1 == null ? (v2 == null ? 0 : -1) : (v2 == null ? 1 : ((Comparable)v1).compareTo(v2));
    }
}
